package com.zyh.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Date;

/**
 * @Author zyh
 * @Date 2024/8/13 15:04
 * @Description 将字符串转为JSON对象
 */

public class JSONDemo3 {
    public static void main(String[] args) {
        String str="{\"age\":20,\"birthday\":1723534942526,\"name\":\"zyh\"}";
        JSONObject jsonObject = (JSONObject) JSON.parse(str);
        String name = jsonObject.getString("name");
        Integer age = jsonObject.getInteger("age");
        Date birthday = jsonObject.getDate("birthday");
        System.out.println(name+"-"+age+"-"+birthday);
        User user = JSON.parseObject(str, User.class);
        System.out.println(user);
    }
}
